import React, { PureComponent } from 'react'
import myaxios from '../../utils/myaxios'
import { withRouter } from 'react-router-dom'

import './index.scss'

class index extends PureComponent {
  state = {
    productData: []
  }

  componentDidMount() {
    myaxios.get('home/floordata').then(data => {
      this.setState({ productData: data.message })
    })
  }

  handleProductClick = () => {
    this.props.history.push("/goodList");
  }

  render() {
    return (
      <div className="prodect-list">
        {this.state.productData.map(v => (
          <div className="product-item" key={v.floor_title.image_src} >
            <h2><img src={v.floor_title.image_src} alt={v.floor_title.name} /></h2>
            {v.product_list.map(vv => (
              <div className="product-item-img" key={vv.image_src} onClick={this.handleProductClick}>
                <img src={vv.image_src} alt="" />
              </div>
            ))
            }
          </div>
        ))}

      </div>
    )
  }
}
export default withRouter(index)
